package com.arpa.wms.controller.wms;

import com.arpa.core.web.MediaTypes;
import com.arpa.core.web.Result;
import com.arpa.ntocc.common.common.Page;
import com.arpa.ntocc.common.common.constant.StrConsts;
import com.arpa.ntocc.common.common.util.ShipmentWarehouseValidate;
import com.arpa.ntocc.common.common.util.UserUtil;
import com.arpa.ntocc.common.security.annotation.NeedLogin;
import com.arpa.ntocc.common.security.annotation.NoReSubmit;
import com.arpa.wms.domain.dto.PrepackagedDTO;
import com.arpa.wms.domain.entity.DeliveryItem;
import com.arpa.wms.domain.entity.Prepackaged;
import com.arpa.wms.domain.entity.PrepackagedItem;
import com.arpa.wms.domain.enums.DeliveryStatusEnum;
import com.arpa.wms.domain.vo.*;
import com.arpa.wms.service.IPrepackagedDistributionService;
import com.arpa.wms.service.IPrepackagedItemService;
import com.arpa.wms.service.IPrepackagedService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.*;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.List;

/**
 * <p>
 * 预打包单 前端控制器
 * </p>
 *
 * @author leo
 * @since 2021-07-02
 */
@Api(tags = "预打包管理")
@RestController
@NeedLogin
@RequestMapping("/prepackaged")
@Log4j2
public class PrepackagedController {

    @Autowired
    private IPrepackagedService prepackagedService;
    @Autowired
    private IPrepackagedDistributionService prepackagedDistributionService;
    @Autowired
    private IPrepackagedItemService prepackagedItemService;




    /**
     * 自动分配
     *
     * @param code
     * @param request
     * @return
     */
    @ApiOperation(value = "自动分配", notes = "自动分配")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "授权token", required = true, paramType = "header", dataType = "String", defaultValue = "Bearer "),
            @ApiImplicitParam(name = "deviceId", value = "设备id", paramType = "header", dataType = "string", defaultValue = "0000000000")
    })
    @ApiResponses(@ApiResponse(code = 0, message = "success", response = PrepackagedVO.class))
    @NeedLogin
    @GetMapping("/autoDistribute/{code}")
    @NoReSubmit
    public Result autoDistribute(@PathVariable String code, HttpServletRequest request) {
        try {
            return prepackagedDistributionService.autoDistribute(code);
        } catch (Exception e) {
            log.error(StrConsts.CATCH_MESSAGE, e);
            return Result.error(e.getMessage());
        }
    }
}
